<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class OperateMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        $create['ip'] = getIp();
        if ($create['ip'] == '127.0.0.1') {
            return $next($request);
        }

        if ($request->all()) {
            $create['parameter'] = json_encode($request->all());
        } else {
            return $next($request);
        }
        $create['admin'] = \Auth::guard('admin')->user()->id;
        $create['url'] = $request->url();
        $create['method'] = $request->method();
        \App\Operate::create($create);

        return $next($request);
    }
}
